﻿@using BlazorAdmin.Client.TestPages.Components
@using Project.Constraints.Models.Request
@using Project.Constraints.UI
@using Project.Constraints.Utils
@inject IUIService UI
<h3>TestPage4</h3>


@* @UI.BuildButton(this).Text("生成").OnClick(BuildExpression).Render() *@
@UI.BuildButton(this).Text("Dialog").OnClick(Open).Render()
<pre>
    @jsonResult
</pre>
<p>可收起，Flex布局</p>
<Project.Web.Shared.Components.QueryConditions LabelWidth="80" ContentWidth="200">
    <Header>
        <Project.Web.Shared.Components.SimpleCondition Label="字段名称" @bind-Value="@condition.Name"></Project.Web.Shared.Components.SimpleCondition>
        <Project.Web.Shared.Components.SimpleCondition Label="字段名称" @bind-Value="@condition.Name"></Project.Web.Shared.Components.SimpleCondition>
        @UI.BuildButton(this).Text("查询").Render()
        @UI.BuildButton(this).Text("查询").Render()
    </Header>

    <ChildContent>
        <Project.Web.Shared.Components.SimpleCondition Label="字段名称123" @bind-Value="@condition.Name"></Project.Web.Shared.Components.SimpleCondition>
        <Project.Web.Shared.Components.SimpleCondition Label="字段名称22" @bind-Value="@condition.Name" EnumValues="@options"></Project.Web.Shared.Components.SimpleCondition>
        <Project.Web.Shared.Components.SimpleCondition Label="字段名称" @bind-Value="@condition.Name"></Project.Web.Shared.Components.SimpleCondition>
        <Project.Web.Shared.Components.SimpleCondition Label="字段名称" @bind-Value="@condition.Name"></Project.Web.Shared.Components.SimpleCondition>
        <Project.Web.Shared.Components.SimpleCondition Label="字段名称" @bind-Value="@condition.Name"></Project.Web.Shared.Components.SimpleCondition>
        <Project.Web.Shared.Components.SimpleCondition Label="字段名称" @bind-Value="@condition.Name"></Project.Web.Shared.Components.SimpleCondition>
        <Project.Web.Shared.Components.SimpleCondition Label="字段名称" @bind-Value="@condition.Name"></Project.Web.Shared.Components.SimpleCondition>
        <Project.Web.Shared.Components.SimpleCondition Label="日期" @bind-Value="@dateTime"></Project.Web.Shared.Components.SimpleCondition>
        <Project.Web.Shared.Components.SimpleCondition Label="字段名称" @bind-Value="@condition.Name"></Project.Web.Shared.Components.SimpleCondition>
        <Project.Web.Shared.Components.SimpleCondition Label="字段名称" @bind-Value="@condition.Name"></Project.Web.Shared.Components.SimpleCondition>
        <Project.Web.Shared.Components.SimpleCondition Label="字段名称" @bind-Value="@condition.Name"></Project.Web.Shared.Components.SimpleCondition>
    </ChildContent>
</Project.Web.Shared.Components.QueryConditions>
<p>不可收起，Grid布局</p>
<Project.Web.Shared.Components.QueryConditions LabelWidth="65" ColumnWidth="200">
    <ChildContent>
        <Project.Web.Shared.Components.SimpleCondition Label="字段名称" @bind-Value="@condition.Name"></Project.Web.Shared.Components.SimpleCondition>
        <Project.Web.Shared.Components.SimpleCondition Label="字段名称" @bind-Value="@condition.Name" EnumValues="@options"></Project.Web.Shared.Components.SimpleCondition>
        <Project.Web.Shared.Components.SimpleCondition Label="字段名称" @bind-Value="@condition.Name"></Project.Web.Shared.Components.SimpleCondition>
        <Project.Web.Shared.Components.SimpleCondition Label="字段名称" @bind-Value="@condition.Name"></Project.Web.Shared.Components.SimpleCondition>
        <Project.Web.Shared.Components.SimpleCondition Label="字段名称" @bind-Value="@condition.Name"></Project.Web.Shared.Components.SimpleCondition>
        <Project.Web.Shared.Components.SimpleCondition Label="字段名称" @bind-Value="@condition.Name"></Project.Web.Shared.Components.SimpleCondition>
        <Project.Web.Shared.Components.SimpleCondition Label="字段名称" @bind-Value="@condition.Name"></Project.Web.Shared.Components.SimpleCondition>
        <Project.Web.Shared.Components.SimpleCondition Label="日期" @bind-Value="@dateTime"></Project.Web.Shared.Components.SimpleCondition>
        <Project.Web.Shared.Components.SimpleCondition Label="字段名称" @bind-Value="@condition.Name"></Project.Web.Shared.Components.SimpleCondition>
        <Project.Web.Shared.Components.SimpleCondition Label="字段名称" @bind-Value="@condition.Name"></Project.Web.Shared.Components.SimpleCondition>
        <Project.Web.Shared.Components.SimpleCondition Label="字段名称" @bind-Value="@condition.Name"></Project.Web.Shared.Components.SimpleCondition>
        <Project.Web.Shared.Components.EmptyCondition LabelWidth="0">
            @UI.BuildButton(this).Text("查询").Render()
            @UI.BuildButton(this).Text("查询").Render()
        </Project.Web.Shared.Components.EmptyCondition>
    </ChildContent>
</Project.Web.Shared.Components.QueryConditions>
@code {
    ConditionUnit condition = new();
    DateTime? dateTime;
    Dictionary<string, string> options = new()
    {
            ["test1"] = "test1",
            ["test2"] = "test2",
            ["test3"] = "test3",
            ["test4"] = "test4",
            ["test5"] = "test5",
    };
    public void BuildExpression()
    {
        // ToJson();
        var exp = condition.BuildExpression<Project.Constraints.Models.Permissions.User>();
        jsonResult = exp.ToString();
    }
    string? jsonResult;
    public void ToJson()
    {
        jsonResult = System.Text.Json.JsonSerializer.Serialize(condition, options: new System.Text.Json.JsonSerializerOptions()
            {
                WriteIndented = true
            });
    }

    public async Task Open()
    {
        var r = await UI.ShowDialogAsync<DialogTest, int>("测试");
        UI.Success($"返回结果: {r}");
        if (r > 100)
        {
            throw new Exception("太大啦");
        }
    }
}
